package frameworks.widgets
{
	public class ResultProxy
	{
		protected var _completeCallback:Array = [];
		protected var _successCallBacks:Array = [];
		protected var _errorCallBack:Array = [];
		protected var _progressCallback:Array = [];
		
		public function ResultProxy()
		{
		}
		
		public function addCompleteCallback(callBack:Function,args:Array=null):void{
			_completeCallback.push({"fun":callBack,"args":args});
		}
		public function addSuccessCallback(callBack:Function,args:Array=null):void{
			_successCallBacks.push({"fun":callBack,"args":args});
		}
		public function addErrorCallback(callBack:Function,args:Array=null):void{
			_errorCallBack.push({"fun":callBack,"args":args});
		}
		public function addProgressCallback(callBack:Function,args:Array=null):void{
			_progressCallback.push({"fun":callBack,"args":args});
		}
		protected function setResultData(callbacks:Array,result:Object):void{
			for each(var item:Object in callbacks){
				if(item["args"]){
					item["args"].push(result);
					item["fun"].apply(null,item["args"]);
				}else{
					item["fun"](result);
				}
			}
		}
		
		public function setSuccessData(result:Result=null):void{
			setResultData(_successCallBacks, result);
			setResultData(_completeCallback, result);
		}
		public function setErrorData(result:Result=null):void{
			setResultData(_errorCallBack, result);
			setResultData(_completeCallback, result);
		}
		public function setProgressData(data:Object=null):void{
			setResultData(_progressCallback, data);
		}
	}
}